﻿<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    :disabled="!addState"
                    @click="exportExcel"
                >导出</el-button>
                <!-- <el-button
                    type="primary"
                    icon="el-icon-plus"
                    v-show="orgType==1"
                    @click="opAdd"
                >新增</el-button> -->
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    :disabled="!addState"
                    @click="opBatchSend"
                >发货</el-button>
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px;margin-right: 20px;">
                    <el-row type="flex" style="flex-wrap:wrap" :gutter="20">
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="订单编号" label-width="100px" style="width: 100%;">
                                <el-input
                                    placeholder="---请输入订单编号---"
                                    v-model="queryList.purchaseOrderCode"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item v-if="orgType=='1'" label="要货订单号" label-width="100px" style="width: 100%;">
                                <el-input
                                    placeholder="---请输入要货订单号---"
                                    v-model="queryList.applyOrderCode"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="申请单位" label-width="100px" style="width: 100%;">
                       
                                <sc-auto-complete
                                    :orgType="2"
                                    :queryType="'store/search'"
                                    :placeholder="'---请输入申请单位---'"
                                    v-model="queryList.storeName"
                                    @handleSelect="(e)=>{this.queryList.storeName=e.storeName}"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="单据状态" label-width="100px" style="width: 100%;">
                                <el-select
                                    placeholder="---请选择状态---"
                                    v-model="queryList.status"
                                    style="width: 100%;"
                                >
                                    <el-option label="---请选择---" value />
                                    <el-option
                                        v-for="item in optionsState"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="物料编码" label-width="100px" style="width: 100%;">
                                <el-input
                                    placeholder="---请输入物料编码---"
                                    v-model="queryList.materialCode"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                                <el-form-item label="物料名称" label-width="100px" style="width: 100%;">
                                    <el-input
                                        placeholder="---请输入名称---"
                                        v-model="queryList.materialName"
                                        style="width: 100%;"
                                    />
                                </el-form-item>

                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="供应商名称" label-width="100px" style="width: 100%;">
                       
                                <sc-auto-complete
                                    :orgType="3"
                                    :queryType="'supplier/search'"
                                    :placeholder="'---请输入供应商名称---'"
                                    v-model="queryList.supplierName"
                                    @handleSelect="(e)=>{this.queryList.supplierName=e.supplierName}"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="物料发货状态" label-width="100px" style="width: 100%;">
                                <el-select
                                    placeholder="---请选择物料发货状态---"
                                    v-model="queryList.purchaseOrderSendStatus"
                                    style="width: 100%;"
                                    
                                >
                                    <el-option label="---请选择---" value />
                                    <el-option
                                        v-for="item in optionsPurchaseOrderSendStatus"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                       
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="下单人" label-width="100px" style="width: 100%;">
                                <el-input
                                    placeholder="---请输入下单人---"
                                    v-model="queryList.createName"
                                    style="width: 100%;"
                                />
                            </el-form-item>
                        </el-col>
                       
                       
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
                            <el-form-item label="订单类型" label-width="100px" style="width: 100%;">
                                <el-select
                                    placeholder="---请选择订单类型---"
                                    v-model="queryList.orderType"
                                    style="width: 100%;"
                                >
                                    <el-option label="---请选择---" value />
                                    <el-option
                                        v-for="item in optionsPurchaseOrderType"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
                            <el-form-item label="下单时间" label-width="100px" style="width: 100%;">
                                <el-date-picker
                                    v-model="queryList.crDates"
                                    type="datetimerange"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                    format="YYYY-MM-DD HH:mm:ss"
                                    range-separator="-"
                                    unlink-panels="true"
                                    start-placeholder="开始时间"
                                    end-placeholder="结束时间"
                                    style="width: 100%"
                                    :default-time="defaultTime"
                                />
                            </el-form-item>
                        </el-col>
                    </el-row>
                   
                   
				   <!-- <el-form-item v-if="orgType=='3'" label="要货订单号" label-width="100px">
				       <el-input
				           placeholder="---请输入要货订单号---"
				           v-model="queryList.applyOrderCode"
				           style="width: 300px"
				       />
				   </el-form-item> -->
                    

                  
                    
                   
                  
                   
                   
                   
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <!--酒业-->
        <el-main class="nopadding" v-if="orgType==1">
            <scTable
                ref="mytable"
                :queryType="'purchase-order/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                :pageSize="10"
                row-key="purchaseOrderId"
                
                border
                show-summary
                remoteSummary
                 @row-click="rowClick"
                :row-style="selectedStyle"
            >
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="序号" type="index" width="60" />
                <el-table-column label="申请时间" prop="purchaseDate" width="120" sortable>
                    <template #default="scope">{{scope.row.purchaseDate?.slice(0,10)}}</template>
                </el-table-column>
               
                <el-table-column label="申请单位" prop="storeName" width="280" sortable></el-table-column>
                <el-table-column label="订单编号" prop="purchaseOrderCode" width="200" sortable>
                    <template #default="scope"> <span class="el-span-text" @click="opShow(scope.row, scope.$index)">{{scope.row.purchaseOrderCode}}</span></template>
                </el-table-column>
                
                <el-table-column label="物料名称"  prop="materialDesc" width="140" sortable  show-overflow-tooltip></el-table-column>

                <el-table-column label="申请数量" prop="afterQty" width="140" sortable></el-table-column>
                <el-table-column label="集采下单数量" prop="confirmQty" width="140" sortable></el-table-column>
                <el-table-column label="供应商接单数量" prop="receiveQty" width="150" sortable>
                    <template #default="scope">
                        <span v-if="scope.row.status==0 || scope.row.status==2">/</span>
                        <span v-else>{{scope.row.receiveQty}}</span>
                    </template>
                </el-table-column>

               
                <el-table-column label="金额" prop="receiveAmount" width="120" sortable>
                    <template #default="scope">{{scope.row.receiveAmount?.toFixed(2)}}</template>
                </el-table-column>
                <el-table-column label="类型" prop="purchaseOrderType" width="100" sortable>
                    <template #default="scope">
                        <el-tag type="success" effect="plain" v-if="scope.row.purchaseOrderType==1">补发</el-tag>
                        <el-tag type="danger" effect="plain" v-else>退货</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="供应商" prop="supplierName" width="200" sortable></el-table-column>
                <el-table-column label="申请人" prop="createName" width="100" sortable ></el-table-column>
                <el-table-column label="退货编号" prop="afterOrderCode" width="160" sortable >
                    <template #default="scope"> <span class="el-span-text" @click="opAfterShow(scope.row, scope.$index)">{{scope.row.afterOrderCode}}</span></template>
                </el-table-column>
                <!-- <el-table-column label="门店要货编号" prop="applyOrderCode" width="160" sortable >
                    <template #default="scope"> <span class="el-span-text" @click="opApplyShow(scope.row, scope.$index)">{{scope.row.applyOrderCode}}</span></template>
                </el-table-column> -->
				<el-table-column  label="要货单位" prop="purchaseUnityName" width="120" sortable></el-table-column>

                <el-table-column label="单据状态" prop="statusDesc" width="120" sortable></el-table-column>
                <el-table-column label="物料发货状态" prop="sendStatusDesc" width="150" sortable >
                    <template #default="scope" >
                        <!--退货类型:退货-->
                        <span v-if="scope.row.purchaseOrderType==2">/</span>
                        <!--退货类型:补发 且 待接单, 完成-->
                        <span v-else-if="scope.row.purchaseOrderType==1 && (scope.row.status==3 ||scope.row.status==5)">{{scope.row.sendStatusDesc}}</span>
                        <span v-else>/</span>
                    </template>
                </el-table-column>
             
                <el-table-column label="备注" prop="remarks" width="180" sortable></el-table-column>
               
                <el-table-column label="操作" fixed="right" align="right" width="240">
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opShow(scope.row, scope.$index)"
                            >查看</el-button>
                           

                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==2"
                                @click="opReceive(scope.row, scope.$index)"
                            >接单</el-button>

                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==0"
                                @click="opEdit(scope.row, scope.$index)"
                            >编辑</el-button>
                           
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==8"
                                @click="opConfirm(scope.row, scope.$index)"
                            >确认</el-button>
                            <el-button
                                text
                                type="danger"
                                size="small"
                                v-show="scope.row.status==2"
                                @click="opCancel(scope.row, 3)"
                            >撤回</el-button>
                            <el-button
                                text
                                type="danger"
                                size="small"
                                v-show="scope.row.status==0 || scope.row.status==3 || scope.row.status==8"
                                @click="opClose(scope.row, 9)"
                            >终止</el-button>
                          
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <!--供应商-->
        <el-main class="nopadding" v-if="orgType==3">
            <scTable
                ref="mytable"
                :queryType="'purchase-order/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                :pageSize="10"
                row-key="purchaseOrderId"
                :row-class-name="setRowClass"
                border
                show-summary
                remoteSummary
                @row-click="rowClick"
                :row-style="selectedStyle"
            >
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="序号" type="index" width="60" />
                <el-table-column label="下单时间" prop="createTime" width="120" sortable>
                    <template #default="scope">{{scope.row.createTime?.slice(0,10)}}</template>
                </el-table-column>
               
                <el-table-column label="申请单位" prop="storeName" width="280" sortable></el-table-column>
                <el-table-column label="订单编号" prop="purchaseOrderCode" width="200" sortable>
                    <template #default="scope"> <span class="el-span-text" @click="opShow(scope.row, scope.$index)">{{scope.row.purchaseOrderCode}}</span></template>
                </el-table-column>
               
                <el-table-column label="物料名称"  prop="materialDesc" width="140" sortable  show-overflow-tooltip></el-table-column>
                <el-table-column label="集采下单数量" prop="confirmQty" width="140" sortable ></el-table-column>
                <el-table-column label="实际接单数量" prop="receiveQty" width="150" sortable >
                    <template #default="scope">
                        <span v-if="scope.row.status==0 ||scope.row.status==2">/</span>
                        <span v-else>{{scope.row.receiveQty}}</span>
                    </template>
                </el-table-column>

                <el-table-column label="金额" prop="receiveAmount" width="120" sortable>
                    <template #default="scope">{{scope.row.receiveAmount?.toFixed(2)}}</template>
                </el-table-column>
                <el-table-column label="类型" prop="purchaseOrderType" width="100" sortable>
                    <template #default="scope">
                        <el-tag type="success" effect="plain" v-if="scope.row.purchaseOrderType==1">补发</el-tag>
                        <el-tag type="danger" effect="plain" v-else>退货</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="供应商" prop="supplierName" width="200" sortable></el-table-column>
                <el-table-column label="下单人" prop="createName" width="100" sortable></el-table-column>

                <el-table-column  label="采购单位" prop="purchaseUnityName" width="120" sortable></el-table-column>
                <el-table-column label="单据状态" prop="statusDesc" width="120" sortable></el-table-column>
                <el-table-column label="物料发货状态" prop="sendStatusDesc" width="150" sortable >
                    <template #default="scope" >
                       <!--退货类型:退货-->
                       <span v-if="scope.row.purchaseOrderType==2">/</span>
                        <!--退货类型:补发 且 待接单, 完成-->
                        <span v-else-if="scope.row.purchaseOrderType==1 && (scope.row.status==3 ||scope.row.status==5)">{{scope.row.sendStatusDesc}}</span>
                        <span v-else>/</span>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remarks" width="180" sortable></el-table-column>
                <el-table-column label="操作" fixed="right" align="right" width="240">
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opShow(scope.row, scope.$index)"
                            >查看</el-button>
                            
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==2"
                                @click="opReceive(scope.row, scope.$index)"
                            >接单</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==2"
                                @click="opCancel(scope.row, 1)"
                            >退回</el-button>
                           
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="(scope.row.purchaseOrderType==0 || scope.row.purchaseOrderType==1) && scope.row.status==5"
                                @click="opSend(scope.row, scope.$index)"
                            >发货</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="(scope.row.purchaseOrderType==0 || scope.row.purchaseOrderType==1)  && scope.row.status==5"
                                @click="opSendDetail(scope.row, scope.$index)"
                            >发货明细</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>

    <save-dialog
        v-if="dialogSave"
        ref="saveDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSave = false"
    ></save-dialog>

    <detail-dialog
        v-if="dialogDetail"
        ref="detailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogDetail = false"
    ></detail-dialog>

    <receive-dialog
        v-if="receiveSave"
        ref="receiveDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="receiveSave = false"
    ></receive-dialog>

    <edit-dialog
        v-if="editSave"
        ref="editDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="editSave = false"
    ></edit-dialog>

    <send-dialog
        v-if="dialogSend"
        ref="sendDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSend = false"
    ></send-dialog>

    <send-detail-dialog
        v-if="dialogSendDetail"
        ref="sendDetailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSendDetail = false"
    ></send-detail-dialog>

    <confirm-dialog
        v-if="confirmSave"
        ref="confirmDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="confirmSave = false"
    ></confirm-dialog>

    <apply-detail-dialog
        v-if="dialogApplyDetail"
        ref="applyDetailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogApplyDetail = false"
    ></apply-detail-dialog>
</template>

<script>
import applyDetailDialog from "../../../apply/order/detail";
import confirmDialog from "./confirm";
import saveDialog from "./save";
import detailDialog from "./detail";
import receiveDialog from "./receive";
import editDialog from "./edit";
import sendDialog from "./send";
import sendDetailDialog from "./sendDetail";
import publicjs from "@/api/model/publicjs";
import tool from "@/utils/tool";
import config from "@/config";

export default {
    name: "purchaseOrderAfter",
    components: {
        applyDetailDialog,
        confirmDialog,
        saveDialog,
        detailDialog,
        sendDialog,
        sendDetailDialog,
        receiveDialog,
        editDialog,
        publicjs,
    },
    data() {
        return {
            dialogApplyDetail:false,
            confirmSave:false,
            dialogSave:false,
            orgType: 0,
            dialogDetail: false,
            receiveSave: false,
            editSave:false,
            dialogSend: false,
            dialogSendDetail: false,
            showCondition: false,
            selectionRows: [],
            pkList: ["purchaseOrderId"],
            columnList: [],
            OrderList: { purchaseOrderId: "Asc" },
            queryList: {},
            defaultQuery: {},
            result: "", // 运行结果
            props1: {
                checkStrictly: true,
                emitPath: false,
            },
            supplierProps: {
                label: "supplierName",
                value: "supplierId",
            },
            storeProps: {
                label: "storeName",
                value: "storeId",
            },
            addState: true, //可以增加
            editState: true, //可以修改
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
            optionsState: [],
            optionsPurchaseOrderSendStatus:[],
            materialTypeTree: [],
            optionsPurchaseOrderType:[],//订单类型
            activeRowIndex: null, // 存储被点击行的索引
            defaultTime:[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ]
        };
    },
    methods: {
        //查看要货订单详情
        opApplyShow(row) {
            this.dialogApplyDetail = true;
            this.$nextTick(() => {
                this.$refs.applyDetailDialog.setData(row);
                this.$refs.applyDetailDialog.open("Show");
            });
        },
        //查看退货订单详情
        opAfterShow(row)
        {
           console.log(row.afterOrderCode) 
           this.$router.push({ path: '/afterOrder', query: { afterOrderCode: row.afterOrderCode} }); 
        },
        //添加
        opAdd() {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.open("Add");
            });
        },
        //编辑
        opEdit(row) {
            this.editSave = true;
            this.$nextTick(() => {
                this.$refs.editDialog.open("Edit").setData(row);
            });
        },
        //复制
        opCopy(row) {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog
                    .open("Add")
                    .setData({ ...row, purchaseProtocolCode: "" });
            });
        },
        //接单
        opReceive(row) {
            this.receiveSave = true;
            this.$nextTick(() => {
                this.$refs.receiveDialog.setData(row);
                this.$refs.receiveDialog.open("Add");
            });
        },
        //确认
        opConfirm(row) {
            this.confirmSave = true;
            this.$nextTick(() => {
                this.$refs.confirmDialog.setData(row);
                this.$refs.confirmDialog.open("Add");
            });
        },
        //发货
        opSend(row) {
            this.dialogSend = true;
            this.$nextTick(() => {
                this.$refs.sendDialog.setData([row.purchaseOrderId]);
                this.$refs.sendDialog.open("Send");
            });
        },
        //退款
        async opRefund(row){
            try {
                var returnValue = await this.$API.auth.GetProcessApi.get(
                    "purchase-order/refund/"+row.purchaseOrderId,
                    { }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //批量发货
        opBatchSend() {
            if (this.selectionRows.length == 0) {
                this.$message.success("请选择要发货的订单");
                return;
            }
            const storeId = this.selectionRows[0].storeId;
            let sendState = true;
            this.selectionRows.forEach((element) => {
                //未接单无法发货
                if (element.status != 3) {
                    this.$message.error(`【${element.purchaseOrderCode}】该要货单无法发货`);
                    sendState = false;
                    return;
                }

                //已全部发货完成
                if (element.sendStatus == 2) {
                    this.$message.error( `【${element.purchaseOrderCode}】该要货单已全部发货`);
                    sendState = false;
                    return;
                }

                if (element.storeId != storeId) {
                    this.$message.error("请选择相同的要货单位订单");
                    sendState = false;
                    return;
                }
            });
            if (sendState) {
                const purchaseOrderIds = this.selectionRows.map(
                    (p) => p.purchaseOrderId
                );
                this.dialogSend = true;
                this.$nextTick(() => {
                    this.$refs.sendDialog.setData(purchaseOrderIds);
                    this.$refs.sendDialog.open("Send");
                });
            }
        },
        //发货明细
        opSendDetail(row) {
            this.dialogSendDetail = true;
            this.$nextTick(() => {
                this.$refs.sendDetailDialog.setData(row.purchaseOrderId);
                this.$refs.sendDetailDialog.open("Send");
            });
        },
        //查看
        opShow(row) {
            this.dialogDetail = true;
            this.$nextTick(() => {
                this.$refs.detailDialog.open("Show").setData(row);
            });
        },
        //设置状态
        async setStatus(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    row.status == 0
                        ? "purchase-order/disabled"
                        : "purchase-order/enable",
                    { purchaseOrderIds: [row.purchaseOrderId] }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //撤单
        async opCancel(row,stauts) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post("purchase-order/cancel",
                    { purchaseOrderId:row.purchaseOrderId,status:stauts}
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //终止
        async opClose(row,stauts)
        {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post("purchase-order/close",
                    { purchaseOrderId:row.purchaseOrderId,status:stauts}
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //删除
        async opDelete(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "purchase-order/delete",
                    { purchaseOrderIds: [row.purchaseOrderId] }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        //本地更新数据
        handleSaveSuccess(data, mode) {
            if (mode == "Add") {
                this.$refs.mytable.refresh();
            } else if (mode == "Edit") {
                this.$refs.mytable.refresh();
            }
        },
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.queryList = {...this.defaultQuery};
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["PurchaseOrderStatus","PurchaseOrderSendStatus","OrderType"] }
                );
                if (returnValue.status == 200) {
                    this.optionsState = returnValue.response.find(
                        (p) => p.code == "PurchaseOrderStatus"
                    ).optionsDetails;

                    this.optionsPurchaseOrderSendStatus = returnValue.response.find(
                        (p) => p.code == "PurchaseOrderSendStatus"
                    ).optionsDetails;

                    this.optionsPurchaseOrderType = returnValue.response.find(
                        (p) => p.code == "OrderType"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "material-type/tree",
                    { status: 1 }
                );
                if (returnValue.status == 200) {
                    this.materialTypeTree = returnValue.response;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //供应商
        async supplierSelectProcess(rowData) {
            this.queryList.suppliers = [];
            this.queryList.supplierIds = [];
            if (rowData && rowData.length > 0) {
                rowData.map((p, index) => {
                    if (p) {
                        debugger;
                        this.queryList.suppliers = [
                            ...this.queryList.suppliers,
                            {
                                supplierId: p.supplierId,
                                supplierName: p.supplierName,
                            },
                        ];
                        this.queryList.supplierIds = [
                            ...this.queryList.supplierIds,
                            p.supplierId,
                        ];
                    }
                });
            }
            await this.opBindData();
        },
        //店铺
        async storeSelectProcess(rowData) {
            this.queryList.stores = [];
            this.queryList.storeIds = [];
            if (rowData && rowData.length > 0) {
                rowData.map((p, index) => {
                    if (p) {
                        debugger;
                        this.queryList.stores = [
                            ...this.queryList.stores,
                            {
                                storeId: p.storeId,
                                storeName: p.storeName,
                            },
                        ];
                        this.queryList.storeIds = [
                            ...this.queryList.storeIds,
                            p.storeId,
                        ];
                    }
                });
            }
            await this.opBindData();
        },
        //导出
        async exportExcel() {
            try {
                var response = await this.$API.auth.PostDownApi.post(
                    "purchase-order/export",
                    this.queryList
                );
                // 获取 Content-Disposition 头部信息
                debugger;
                const headers = new Headers(response.headers);
                console.log(headers);
                let fileName = headers.get("File-Name");
                console.log(fileName);
                fileName = decodeURIComponent(fileName);
                console.log(fileName);
                if (!fileName || fileName == "null") {
                    fileName = "采购订单.xlsx";
                }
                console.log(fileName);
                const blob = new Blob([response.data], {
                    type: "application/xlsx",
                });
                // 创建一个临时的 URL 对象，指向下载的 Blob 数据
                const url = window.URL.createObjectURL(blob);
                // 创建一个 <a> 元素，设置其 href 属性为 URL，并触发点击
                const a = document.createElement("a");
                a.href = url;
                a.download = fileName; // 下载时显示的文件名为从头信息中获取的文件名
                document.body.appendChild(a); // 将 <a> 元素添加到 DOM 中
                a.click(); // 模拟点击下载
                document.body.removeChild(a); // 下载完成后移除 <a> 元素
                window.URL.revokeObjectURL(url); // 释放 Blob 对象
            } catch (error) {
                this.loading = false;
                this.$alert(error.message, "提示", { type: "error" });
                return false;
            }
        },
        async formatDate(date) {
            if (date) {
                const dateNew = tool.formatDate(new Date(date), 1);
                console.log(dateNew);
            }
            return "";
        },
         //行点击
         rowClick(row, event, column){
            console.log("行点击",row);
            this.activeRowIndex = row.purchaseOrderId;
        },
        //选中样式
        selectedStyle({ row, rowIndex })
        {
            if (this.activeRowIndex === row.purchaseOrderId) {
                return { backgroundColor: '#87CEFF'};
            }
            return {};
        },
        setRowClass({ row, rowIndex }) {
            let rowClass = "";
            if (this.selectionRows.includes(row)) {
                rowClass += " selected-row-color";
            }

            //终止
            if (row.status == 9) {
                rowClass += " selected-row-color-grey";
            }
            return rowClass;
        },
    },
    async mounted() {
        this.defaultQuery = JSON.parse(this.$route.meta.query);
        var purchaseOrderCode=this.$route.query.purchaseOrderCode;

        if(!this.defaultQuery){
            this.defaultQuery={"purchaseOrderType":[0]}
        }
       this.queryList={...this.defaultQuery};
        if(purchaseOrderCode){
            this.queryList.purchaseOrderCode=purchaseOrderCode
        }
        this.orgType = tool.data.get("USER_INFO").AccountType;
        await this.initOptions();
        await this.opBindData();
    },
};
</script>
<style>
.el-span-text{
    cursor: pointer;
}

.el-table .selected-row-color {
    background-color: #b8dcff !important;
}
.el-table .selected-row-color-grey {
    color: #000000 !important;
    text-decoration: line-through; /* 删除线 */
}
</style>
